
package com.universal.schedule.broadcast;

import com.google.gson.Gson;
import com.universal.schedule.enity.Alarm;
import com.universal.schedule.service.AlarmServiceBroadcastReciever;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

public class AlarmAlertBroadcastReciever extends BroadcastReceiver {
	private Gson mGson= new Gson();
	@Override
	public void onReceive(Context context, Intent intent) {
		Toast.makeText(context, "铃声响了!", Toast.LENGTH_SHORT).show();
		Intent mathAlarmServiceIntent = new Intent(
				context,
				AlarmServiceBroadcastReciever.class);
		context.sendBroadcast(mathAlarmServiceIntent, null);

		StaticWakeLock.lockOn(context);
		String alarmString = intent.getStringExtra("alarm");
		final Alarm alarm = mGson.fromJson(alarmString, Alarm.class);

		Intent mathAlarmAlertActivityIntent;

		mathAlarmAlertActivityIntent = new Intent(context, AlarmAlertActivity.class);

		mathAlarmAlertActivityIntent.putExtra("alarm", alarm);

		mathAlarmAlertActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

		context.startActivity(mathAlarmAlertActivityIntent);
	}

}
